<?php 

require("./func/global_conn.php");


define("MAILID", "edt.precisions@gmail.com");
define("PWMAIL", "edt.precisions123");
define("NAMEAPP", "EDT");


require dirname(__FILE__).'/func/mailer/PHPMailerAutoload.php';
function mailer($to=null,$subject='',$body='',$altBody = 'This is the body in plain text for non-HTML mail clients',$fullName = ''){
	$mail = new PHPMailer;

	$mail->isSMTP();                                      // Set mailer to use SMTP
	$mail->Mailer = "smtp";
	$mail->Host = "smtp.gmail.com";
	$mail->Port = 587;
	$mail->SMTPAuth = true;                               // Enable SMTP authentication
	$mail->Username = MAILID;                            // SMTP username
	$mail->Password = PWMAIL;                           // SMTP password
	$mail->SMTPSecure = 'tls';                            // Enable encryption, 'ssl' also accepted

	$mail->From = MAILID;
	$mail->FromName = 'EDT';
	
	$mail->addAddress($to, $fullName );  // Add a recipient
	// $mail->addAddress('ellen@example.com');               // Name is optional
	// $mail->addReplyTo('info@example.com', 'Information');
	// $mail->addCC('cc@example.com');
	// $mail->addBCC('bcc@example.com');

	$mail->WordWrap = 5000;                                 // Set word wrap to 50 characters
	// $mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
	// $mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
	$mail->isHTML(true);                                  // Set email format to HTML

	$mail->Subject = $subject;
	$mail->Body    = $body;
	$mail->AltBody = $altBody;

	// if(!$mail->send()) {
	   // echo 'Message could not be sent.';
	   // echo 'Mailer Error: ' . $mail->ErrorInfo;
	   // exit;
	// }

	// echo 'Message has been sent';
	return $mail->send();
}


if(!empty($_POST)){

	mailer($_POST['email'],$_POST['subject'],$_POST['message'],$_POST['firstname']);
	
	header("Location: /home");
	
}

?>
